package com.situ.mall.controller.front;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.entity.Category;
import com.situ.mall.entity.Product;
import com.situ.mall.service.ICategoryService;
import com.situ.mall.service.IProductService;

@Controller
@RequestMapping("/product")
public class FrontProductController {
	@Autowired
	private IProductService productService;
	@Autowired
	private ICategoryService categoryService;
	
	@RequestMapping("/selectAll.shtml")
	@ResponseBody
	public List<Product> selectAll() {
		System.out.println("FrontProductController.selectAll()");
		return productService.selectAll();
	}
	
	@RequestMapping("/product.shtml")
	public String product(Model model,int id,Integer categoryId) {
		System.out.println("FrontIndexController.product()");
		System.out.println("id = " + id);
		
		//获取特定Id的产品信息
		Product product = productService.selectProductById(id); 
		//System.out.println("product" + product);
		
		System.out.println("categoryId = " + categoryId);
		//猜你喜欢的相关分类产品
		List<Product> listMYL = productService.selectProductByMaybeYLike(categoryId,id);
		
		//前台分类下拉行
		List<Category> topCategoryList = categoryService.selectTopCategoryList();
		List<Category> secondCategoryList = categoryService.selectSecondCategoryList();
		
		model.addAttribute("topCategoryList", topCategoryList);
		model.addAttribute("secondCategoryList", secondCategoryList);
		model.addAttribute("listMYL",listMYL);
		model.addAttribute("product",product);
		
		return "product";
	}
}
